﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CompanyBussiness;

namespace Website.customer.Control
{
    public partial class cContact : System.Web.UI.UserControl
    {
        SendEmail send = new SendEmail();
        NewsManagement newsMana = new NewsManagement();
        LanguagesManagement languageMana = new LanguagesManagement();
        CompanyBussiness.Category category;
        CompanyBussiness.Language language;
        CompanyBussiness.New news;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies[CONST.COOKIES_LANGUAGE] == null)
            {
                Session[CONST.SESSION_LANGUAGE] = "";
                language = languageMana.GetLanguageByCode("vi-VN");
            }
            else
            {
                Session[CONST.SESSION_LANGUAGE] = Request.Cookies[CONST.COOKIES_LANGUAGE][CONST.COOKIES_LANGUAGE_ID];
                language = languageMana.GetLanguageByID(int.Parse(Session[CONST.SESSION_LANGUAGE].ToString()));
            }
            loadLanguage();
            LoadContact();
        }

        protected void loadLanguage()
        {
            lbName.Text = languageMana.GetTagValueByLanguageIDandTagName("lbName", language.LanguagesID);
            lbEmail.Text = languageMana.GetTagValueByLanguageIDandTagName("lbEmail", language.LanguagesID);
            lbSubjectMail.Text = languageMana.GetTagValueByLanguageIDandTagName("lbSubjectMail", language.LanguagesID);
            lbContentEmail.Text = languageMana.GetTagValueByLanguageIDandTagName("lbContentEmail", language.LanguagesID);
            btnSubmitEmail.Text = languageMana.GetTagValueByLanguageIDandTagName("btnSubmitEmail", language.LanguagesID);
            btnClear.Text = languageMana.GetTagValueByLanguageIDandTagName("btnClear", language.LanguagesID);
        }

        protected void LoadContact()
        {
            news = newsMana.GetNewsOneByCategoryName("MCONTACT", language.LanguagesID);
            lbSubject.Text = news.NewsSubject;
            lbPhoneAndFax.Text = news.NewsIntro;
            addressTEXT.Text = news.NewsSource;
            lnkLink.Text = news.NewsLink;
            lnkLink.NavigateUrl = news.NewsLink;
            litContent.Text = news.NewsContent;

        }

        protected void btnSubmitEmail_Click(object sender, EventArgs e)
        {
            send.SendMailMessage("dienco@hem.vn", txtSubjectMail.Text, txtName.Text, txtEmail.Text, txtContentEmail.Text);
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtEmail.Text = "";
            txtName.Text = "";
            txtSubjectMail.Text = "";
            txtContentEmail.Text = "";
        }
    }
}